package com.mbl.base.modular.base.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mbl.base.core.common.controller.BaseController;
import com.mbl.base.core.utils.UtilHttp;
import com.mbl.base.modular.base.entity.Admin;
import com.mbl.base.modular.base.service.IAdminService;
import com.mbl.base.modular.member.entity.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author lwj
 * @since 2020-03-04
 */
@RestController
@RequestMapping("/base/admin")
public class AdminController extends BaseController<Admin, IAdminService> {
    @Override
    public void machiningAdd(Admin obj) {
        if(StringUtils.isBlank(obj.getPassword())){
            obj.setPassword("123456");
        }
        obj.setPassword(new BCryptPasswordEncoder().encode(obj.getPassword()));
        super.machiningAdd(obj);
    }

    @Override
    public void machiningList(QueryWrapper<Admin> queryWrapper, String condition) {
        final String username = UtilHttp.getPara("username");
        queryWrapper.like(StringUtils.isNotBlank(username), "username", username);
        super.machiningList(queryWrapper, condition);
    }
}

